package com.iweipan.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.iweipan.R;
import com.iweipan.base.WPBaseFragment;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/11/17.
 */

public class ThreeFragment extends WPBaseFragment implements RadioGroup.OnCheckedChangeListener, ViewPager.OnPageChangeListener {


    @BindView(R.id.create_order)
    RadioButton createOrder;
    @BindView(R.id.out_order)
    RadioButton outOrder;
    @BindView(R.id.order_radioGroup)
    RadioGroup orderRadioGroup;
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    private MyFragementViewPagerAdaper myFragementViewPagerAdaper;

    public static ThreeFragment newInstance() {

        Bundle args = new Bundle();

        ThreeFragment fragment = new ThreeFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void initData() {
        orderRadioGroup.setOnCheckedChangeListener(this);
        myFragementViewPagerAdaper = new MyFragementViewPagerAdaper(getChildFragmentManager());
        viewPager.setAdapter(myFragementViewPagerAdaper);
        viewPager.addOnPageChangeListener(this);
    }

    @Override
    public void initDestrory() {

    }

    @Override
    public void initView() {

    }

    @Override
    public View inflaterView(LayoutInflater inflater, ViewGroup container) {
        return inflater.inflate(R.layout.fragment_three, null);
    }


    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.create_order:
                viewPager.setCurrentItem(0);
                break;
            case R.id.out_order:
                viewPager.setCurrentItem(1);
                break;
        }
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        switch (position){
            case 0:
                createOrder.setChecked(true);
                break;
            case 1:
                outOrder.setChecked(true);
                break;
        }

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    private class MyFragementViewPagerAdaper extends FragmentPagerAdapter {

        public MyFragementViewPagerAdaper(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return RechargeWithdrawalFragment.newInstance(position);
        }

        @Override
        public int getCount() {
            return 2;
        }
    }
}
